home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / wdram.arc / WDRAM.ASM next >
Encoding:
Assembly Source File  |  1987-05-24  |  6.6 KB  |  242 lines

  1. TEXT    SEGMENT    PUBLIC WORD 'CODE'
  2.  
  3.  
  4.     ASSUME    CS:TEXT,DS:TEXT,ES:TEXT,SS:TEXT
  5.  
  6. ;    Magic constants.  These are for WD controller, version x.xx.
  7. WDC_SEG    EQU    0C800h        ; Segment for WD ROM BIOS.
  8. WDC_SIZ    EQU    0800h        ; Size, in bytes, of WD ROM BIOS.
  9.  
  10.  
  11.  
  12. ;    This program will relocate the Western Digital Controller
  13. ;    ROM BIOS code into RAM.  If you are fortunate enough to own an
  14. ;    AT&T PC6300, this will do wonders for you disk speeds.
  15. ;
  16. ;    While the AT&T has a 16 bit processor with 16 bit RAM and ROM, 
  17. ;    whenever it tries to run the ROM BIOS on the WDC card, all that
  18. ;    power is wasted trying to read 16 bit instructions off the 8 bit
  19. ;    I/O bus.  The bus converter board 'works', but it take much longer
  20. ;    than necessary.
  21. ;
  22. ;    By relocating the WD code to RAM, we stay away from the bus converter
  23. ;    and its wasteful overhead.  Consequently, you can reformat the
  24. ;    hard disk to an interleave of 4!!.  The best one can normally do
  25. ;    with the AT&T 6300 is 6.  This would appear to be a 50% improvement.
  26. ;
  27. ;    Since I have only one controller to test it on, I tried to avoid the
  28. ;    usual practice of hardcoding constants.  Instead, I look for
  29. ;    the two instructions which will take over the BIOS ints.  From these
  30. ;    MOV instructions, I get the address of WD's INT handler.  Then I
  31. ;    search DOS to see where it has saved those addresses when it proceeded
  32. ;    to steal those vectors for itself.
  33. ;
  34. ;    There are obvious risks with inadvertantly clobbering DOS, but things
  35. ;    seem to work for both DOS 3.1 and DOS 3.3.
  36. ;
  37. ;    Naturally, I will disclaim any and everything.  Still, let me know
  38. ;    if you have any problems, or your version of the WDC has instructions
  39. ;    other than those I am skipping over.  Just DEBUG and disassemble
  40. ;    from C800:0003 and follow the JMP.
  41. ;    
  42. ;    Copyright (c) 1987, Hanover Systems, All Rights Reserved.
  43. ;
  44. ;
  45. ;    Good luck, Chris Smith, Newtown, CT 203-426-0024.
  46. ;
  47.  
  48.  
  49. RAMC800    PROC    FAR
  50.  
  51. ;    OK, Let's reserve room for this mess...              
  52. NEWROM:
  53.     PUSH    DS
  54.     PUSH    ES
  55.     JMP    LOADER
  56.     DB    WDC_SIZ dup (?)
  57.  
  58. ;    Private data area.
  59. VEC4C    DW    -1            ; Offset for INT 13 entry.
  60. VEC64    DW    -1            ; Offset for INT 25 entry.
  61. VECS    DB    0            ; Number vectors found so far.
  62.  
  63. ;    Now, let's copy the ROM stuff from C800:0000 to NEWROM
  64. LOADER:
  65.            MOV    AX,WDC_SEG
  66.     MOV    ES,AX
  67.     MOV    AX,CS
  68.     MOV    DS,AX
  69.     MOV    SI,0
  70.     LEA    DI,NEWROM
  71.     MOV    CX,WDC_SIZ/2
  72.  
  73. COPYROM:
  74.     MOV    AX,ES:[SI]
  75.     MOV    [DI],AX
  76.     ADD    SI,2
  77.     ADD    DI,2
  78.     LOOP    COPYROM
  79.  
  80. ;    Try to find our two magic constants...
  81. ;    We need the addresses stuffed to locations 4C and 64.
  82.  
  83. ;    Find where init code starts...
  84.     CMP    byte ptr NEWROM+3,0EBh    ; This a short jump?
  85.     JNE    BADROM            ; No, give up right here.
  86.     MOV    AL,byte ptr [NEWROM+4]    ; Yes, get offset.
  87.     CBW                ; Use fullword.
  88.     ADD    AX,5            ; Get address init code.
  89.  
  90. ;    Skip over unnecessary instructions.
  91.     MOV    VECS,0            ; Start with nothing on record.
  92.     MOV    CX,100            ; Don't go on forever.
  93.     MOV    SI,AX
  94.     CLD
  95. DECODE:
  96.     CMP    word ptr [SI],0C033h    ; "XOR AX,AX"?
  97.     JE    DEC2            ;   Yes, skip two bytes.
  98.     CMP    word ptr [SI],0D88Eh    ; "MOV DS,AX"?
  99.     JE    DEC2            ;   Yes, skip two bytes.
  100.     CMP    byte ptr [SI],0FAh    ; "CLI"?
  101.     JE    DEC1            ;   Yes, skip it.
  102.     CMP    word ptr [SI],006C4h    ; "LES AX,constant"?
  103.     JE    DEC4            ;   Yes, skip four bytes.
  104.     CMP    word ptr [SI],000A3h    ; "MOV vector,AX"?
  105.     JE    DEC3            ;   Yes, skip it.
  106.     CMP    word ptr [SI],0068Ch    ; "MOV vector,ES"?
  107.     JE    DEC4            ;   Yes, skip it.
  108.     CMP    word ptr [SI],00E8Ch    ; "MOV vector,CS"?
  109.     JE    DEC4            ;   Yes, skip it.
  110.     CMP    word ptr [SI],006C7h    ; "MOV vector, constant"?
  111.     JNE    BADROM            ; No, I don't know what to do!!!
  112.  
  113. ;    We have a constant move into a vector.  See if vector is 4C or 64.
  114.     ADD    SI,2            ; Advance to vector address.
  115.     CMP    word ptr [SI],00064h    ; To vector at 64?
  116.     JE    FOUND64            ; Yes, now we're making progress.
  117.     CMP    word ptr [SI],0004Ch    ; To vector at 4C?
  118.     JNE    DEC4            ; Knock 4 more bytes off this instruction.
  119.  
  120. ;    We found the MOV instruction that sets up vector at 4C.
  121.     MOV    AX,word ptr [SI+2]    ; Get code entry.
  122.     MOV    VEC4C,AX        ; Save for later.
  123.     INC    VECS            ; We found one vector.
  124.     JMP    DEC4            ; Go look for more, if necessary.
  125.  
  126. ;    We found the MOV instruciton that sets up vector at 64.
  127. FOUND64:
  128.     MOV    AX,word ptr [SI+2]    ; Get code entry.
  129.     MOV    VEC64,AX        ; Save for later.
  130.     INC    VECS            ; We found one vector.
  131.     
  132. ;    Advance to next instruction.
  133. DEC4:    INC    SI
  134. DEC3:    INC    SI
  135. DEC2:    INC    SI
  136. DEC1:    INC    SI
  137.     CMP    byte ptr VECS,2        ; We get both vectors yet?
  138.     JE    FIXDOS            ; Yes, now go patch DOS.
  139.     LOOP    DECODE            ; No, keep going for a bit.
  140.     
  141. ;    We weren't able to find our addresses.  Abort.
  142. BADROM:
  143.     LEA    DX,BADROMMSG
  144.     MOV    AH,9        ; Print string function.
  145.     INT    21H        ; Do it.
  146.     
  147.     POP    ES
  148.     POP    DS
  149.     XOR    AX,AX        ; Terminate.
  150.     INT    21H
  151.  
  152.  
  153. BADROMMSG    DB    "Undecodable WD controller BIOS.",0AH,0DH,'$'
  154.     
  155.  
  156.  
  157. ;    Naturally, somebody whose name we won't mention has stolen our
  158. ;    vectors...  Find where that nasty Redmont Wa company has stuffed
  159. ;    them & re-direct them to our RAM based code...
  160.  
  161. ;    First, find where the original 4C vector went...
  162. FIXDOS:
  163.     MOV    AX,VEC4C    ; Search for C800:V_VEC4C
  164.     XOR    BX,BX        ; Start at 0:0
  165. S4C:    CALL    FINDIT        
  166.     JC    FIND64    
  167.     MOV    word ptr ES:[BX],CS    ; Use RAM version instead.
  168.     JMP    S4C        ; Look for at least one more instance.
  169.  
  170. ;    Then, find where the original 64 vector went...
  171. FIND64:    MOV    AX,VEC64    ; Search for C800:V_VEC64
  172.     XOR    BX,BX        ; Start at 0:0
  173. S64:    CALL    FINDIT        
  174.     JC    FIXDMA    
  175.     MOV    word ptr ES:[BX],CS    ; Use RAM version instead.
  176.     JMP    S64        ; Just in case there are any more...
  177.  
  178. ;    We've patched DOS to go to our RAM copy of WD code.
  179. FIXDMA:
  180. ;    If I were going to screw around with the DMA programming, I'd
  181. ;    put my patches here.  So far, nothing seems to help.
  182.  
  183.  
  184. ;    Now, do a TSR number, leaving the ROM stuff here.
  185.     LEA    DX,ALLDONEMSG
  186.     MOV    AH,9        ; Print string function.
  187.     INT    21H        ; Do it.
  188.  
  189.     MOV    AX,3100H
  190.     MOV    DX,800H/10H    ; Get amount to remain resident.
  191.     POP    ES
  192.     POP    DS
  193.     INT    21H
  194.  
  195. ALLDONEMSG    DB    "WD BIOS moved to RAM.",0AH,0DH
  196.         DB    "Hanover Systems, (c) 1987",0AH,0AH,0DH,'$'
  197.  
  198. RAMC800    ENDP
  199.  
  200.  
  201.  
  202. ;    Subroutine to scan memory for patchable address inside DOS.
  203. ;    AX=value to match, (Don't forget C800: follows).  BX is offset
  204. ;    to start with.  Set C flag if we don't find anything between offset
  205. ;    0 and FFFE.
  206.  
  207. FINDIT    PROC    NEAR
  208.     XOR    DX,DX
  209.     MOV    ES,DX
  210. FINDL1:    CMP    byte ptr ES:[BX],AL    
  211.     JNE    FINDL2        ; Didn't match offset.
  212.     CMP    byte ptr ES:[BX+1],AH
  213.     JNE    FINDL2
  214.     CMP    word ptr ES:[BX+2],WDC_SEG
  215.     JE    FINDL3        ; We matched segment!!
  216. FINDL2:    ADD    BX,1
  217.     JNZ    FINDL1
  218.     STC            ; Indicate not found.
  219.     RET
  220.              
  221. FINDL3:    ADD    BX,2        ; Point at segment.
  222.     CLC            ; Indicate we found our man.
  223.     RET 
  224.             
  225. FINDIT    ENDP
  226.  
  227. TEXT    ENDS
  228.  
  229.     END
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.              
  241.  
  242.